package com.zhoubg.spring.transaction.demo2.dao.impl;

import com.zhoubg.spring.transaction.demo2.dao.AccountDao;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Create by Zhoubg at 2017/10/18
 */
@Repository
public class AccountDaoImpl implements AccountDao {

    @Resource
    private JdbcTemplate JdbcTemplate;

    /**
     *
     * @param account 转出账号
     * @param money 装出金额
     */
    public void outMoney(String account, Double money) {
        String sql = "update account set money = money-? where name = ?";
        JdbcTemplate.update(sql, money, account);
    }

    /**
     *
     * @param account 转入账号
     * @param money 转入金额
     */
    public void inMoney(String account, Double money) {
        String sql = "update account set money = money+? where name = ?";
        JdbcTemplate.update(sql,money,account);
    }
}
